$(function() {
    var bdbplatDomainLine = {
        /* 初始数据 */
        defData: {
            pageSize: 20,
            platDomainId: bdbMain.getUrlParams()['id'],
            lineSelAreaInitialPosition: []
        },

        /* 页面状态 */
        pageState: {
            page: 1, // 分页值.
            noData: 'def' // search: 没有匹配的结果; def: 暂无记录.
        },
        resetPageState: function() {
            this.pageState = {
                page: 1,
                noData: 'def'
            };

            this.list();
        },

        /* 添加 */
        addEvent: function() {
            var _this = this,
                formVerify;

            formVerify = $('#bdb-platdomainpolicy-add-form').validate({
                errorElement: "div",
                errorPlacement: function(error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        element.parents(".bdb-vc").find('.help-block').remove();
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.addSave(form);
                }
            });

            $('#bdb-platdomainpolicy-add').off('click').on('click', function(e) {
                bdbMain.mLRManag({mask: true});
                _this.addDefDataProc(formVerify);
            });
        },
        addDefDataProc: function(formVerify) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/PlatDomainLine/policyLineInit', {
                plat_domain_id: _this.defData.platDomainId
            }, function(response) {
                if (response.code == 0) {
                    _this.addDefDataProcTpl(response.data, formVerify);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        addDefDataProcTpl: function(data, formVerify) {
            var _this = this,
                lineHtml = '<li data-type="all">全部</li>',
                sublineHtml = '',
                policyHtml = '',
                ele = $('#bdb-platdomainpolicy-add-form');

            // 平台域名名称及域.
            ele.find('.title span').text(data.domain);

            // view.
            $.each(data.lineList, function(key, val) {
                lineHtml += '<li data-type="' + key + '">' + val.line_name + '</li>';
                sublineHtml += '<div data-type="' + key + '">';
                $.each(val.subLines, function(ky, vl) {
                    sublineHtml += '<div>\
                                        <span class="area-title"><i class="check-icon checkNo"></i>' + vl.line_name + '</span>\
                                    </div>\
                                    <ul class="bdb-clearfix">';

                    if (typeof vl.subLines == 'object') {
                        $.each(vl.subLines, function(k, v) {
                            sublineHtml += '<li class="area-subline" data-id="' + val.id + '_' + v.id + '">\
                                               <i class="check-icon checkNo"></i>' + v.line_name + '\
                                            </li>';
                        });
                    } else {
                        sublineHtml += '<li class="area-subline" data-id="' + val.id + '_' + vl.id + '">\
                                           <i class="check-icon checkNo"></i>' + vl.line_name + '\
                                        </li>';
                    }

                  sublineHtml += '</ul>';
                });
                sublineHtml += '</div>';
            });
            ele.find('.platdomainpolicy-view-left ul').html(lineHtml);
            ele.find('.platdomainpolicy-view-right').html(sublineHtml);

            // 策略.
            $.each(data.policyList, function(i, n) {
                policyHtml += '<option value="' + n.policy_id + '">' + n.policy_name + '</option>';
            });
            ele.find('#policy_id-add').html(policyHtml);

            // 指向初始化.
            ele.find('#cname-add').hide();
            ele.find('#ips-add').show();
            ele.find('.platdomainpolicy-policy-right').show();

            bdbMain.mLSleep({loading: false}, function() {
                $(".bdbBlankEle").bdbDialog({
                    ele: '#bdb-platdomainpolicy-add-dialog',
                    formObj: formVerify,
                    form: $('#bdb-platdomainpolicy-add-form'),
                    reset: true
                });

                // areaEelTop.
                if (_this.defData.lineSelAreaInitialPosition == '') {
                    bdbMain.mLSleep({}, function() {
                        var areaEles = $('#bdb-platdomainpolicy-add-form .platdomainpolicy-view-right div[data-type]');
                        if (areaEles.length <= 1) {
                            return ;
                        }

                        $.each(areaEles, function(i, n) {
                            _this.defData.lineSelAreaInitialPosition[$(n).attr('data-type')] = $(n).position().top;
                        });
                    }, 100);
                }

                ele.find('.platdomainpolicy-view-right').scrollTop(0);
            });
        },
        addSave: function(form) {
            var _this = this,
                recordLineIdArr = [],
                recordLineIds = '',
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            var ips = '',
                ipsArr = [],
                checkedEles = form.find('.check-icon.checkYes');

            if (form.find('#record_type-add').val() == 'A') {
                ips = form.find('#ips-add').val().trim();
                ipsArr = ips.split('\n');
                ips = ipsArr.join(',');
            } else {
                ips = form.find('#cname-add').val();
            }

            // 选中项.
            $.each(checkedEles, function(i, n) {
                if ($(n).parent('li').length) {
                    recordLineIdArr.push($(n).parent('li').attr('data-id'));
                }
            });
            recordLineIds = recordLineIdArr.join(',');

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/PlatDomainLine/addLine', {
                plat_domain_id: _this.defData.platDomainId,
                record_line_ids: recordLineIds,
                record_type: form.find('#record_type-add').val(),
                policy_id: form.find('#policy_id-add').val(),
                ttl: form.find('#ttl-add').val(),
                ips: ips
            }, function(response) {
                if (response.code == 0) {
                    $(".js-bdb-dialog-cancel").click();
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '添加成功.'}});
                    bdbMain.mLSleep({}, function() {
                        _this.resetPageState();
                    });
                } else {
                    bdbMain.mLSleep({loading: false, alertHC: {msg: response.msg, maskDown: 99}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 全部下发 */
        allPushEvent: function() {
            var _this = this;
            $('#bdb-platdomainpolicy-allpush').off('click').on('click', function() {
                _this.allPushProc(_this.defData.platDomainId);
            });
        },
        allPushProc: function(id) {
            var _this = this;

            bdbMain.confirm({
                textInfo: {
                    content: '确定要全部下发吗？',
                    btn: {}
                },
                // note: true,
                params: {
                    url: '/PlatDomainLine/batchPushLine',
                    data: {
                        id: id
                    }
                },
                callback: function(ele, params) {
                    _this.allPushCallbackProc(ele, params);
                }
            });
        },
        allPushCallbackProc: function(ele, params) {
            var _this = this;
            ele.hide();

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, loading: true});
            $.post(params.url, {
                plat_domain_id: params.data.id
            }, function(response) {
                if (response.code == 0) {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 1, msg: '全部下发成功'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list({page: bdbMain.pageCheck(_this.pageState.page)});
                            $('.check-all-icon').removeClass('checkAll').addClass('checkNone');
                        });
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alertHC: {msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 批量编辑 */
        batchEditEvent: function() {
            var _this = this;
            $('#bdb-platdomainpolicy-batchedit').off('click').on('click', function() {
                if ($('.bdb-list .check-icon.checkYes').length <= 0) {
                    bdbMain.mLRManag({alert: {type: 2, msg: '请选择要修改的记录行!'}});
                    return ;
                }

                _this.batchEditProc();
            });
        },
        batchEditProc: function() {
            var _this = this,
                idArr = [],
                ids = '',
                idEles = $('.bdb-list .check-icon.checkYes');

            $.each(idEles, function(i, n) {
                idArr.push($(n).parents('.bdb-list-row').attr('data-id'));
            });
            ids = idArr.join(',');

            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/PlatDomainLine/batchEditLineInit', {
                plat_domain_line_ids: ids
            }, function(response) {
                if (response.code == 0) {
                    _this.batchEditDefDataInit(response.data, ids);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        batchEditDefDataInit: function(data, ids) {
            var _this = this;
            $.post('/PlatDomainLine/policyLineInit', {
                plat_domain_id: _this.defData.platDomainId,
                type: 1
            }, function(response) {
                if (response.code == 0) {
                    _this.batchEditTpl(data, response.data, ids);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        batchEditTpl: function(data, initData, ids) {
            var _this = this,
                lineHtml = '',
                policyHtml = '',
                ele = $('#bdb-platdomainpolicy-batchedit-form');

            // 线路.
            $.each(data.list, function(i, n) {
                lineHtml += '<li>' + n.record_line_name + '</li>';
            });
            ele.find('#platdomainpolicy-linelist ul').html(lineHtml);

            // 策略.
            $.each(initData.policyList, function(i, n) {
                policyHtml += '<option value="' + n.policy_id + '">' + n.policy_name + '</option>';
            });

            // 指向初始化.
            ele.find('#cname-batchedit').hide();
            ele.find('#ips-batchedit').show();
            ele.find('.platdomainpolicy-policy-right').show();

            ele.find('#plat_domain_line_ids-batchedit').val(ids);
            ele.find('#platdomainpolicy-selected-line span').text(data.list.length);
            ele.find('#record_line_ids-batchedit').val(data.id);
            ele.find('#policy_id-batchedit').html(policyHtml);
            ele.find('.title span').html(initData.domain);
            _this.batchEditVerify();
        },
        batchEditVerify: function() {
            var _this = this,
                formVerify;

            formVerify = $('#bdb-platdomainpolicy-batchedit-form').validate({
                errorElement: "div",
                errorPlacement: function(error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        element.parents(".bdb-vc").find('.help-block').remove();
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.batchEditSave(form);
                }
            });

            bdbMain.mLSleep({loading: false}, function() {
                var formEle = $('#bdb-platdomainpolicy-batchedit-form');
                $(".bdbBlankEle").bdbDialog({
                    ele: '#bdb-platdomainpolicy-batchedit-dialog',
                    formObj: formVerify,
                    form: formEle,
                    verifyResetInfo: true
                });

                formEle.find('#platdomainpolicy-linelist').scrollTop(0);
            });
        },
        batchEditSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            var ips = '',
                ipsArr = [];

            if (form.find('#record_type-batchedit').val() == 'A') {
                ips = form.find('#ips-batchedit').val().trim();
                ipsArr = ips.split('\n');
                ips = ipsArr.join(',');
            } else {
                ips = form.find('#cname-batchedit').val();
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/PlatDomainLine/batchEditLine', {
                plat_domain_line_ids: form.find('#plat_domain_line_ids-batchedit').val(),
                record_type: form.find('#record_type-batchedit').val(),
                policy_id: form.find('#policy_id-batchedit').val(),
                ttl: form.find('#ttl-batchedit').val(),
                ips: ips
            }, function(response) {
                if (response.code == 0) {
                    $('.js-bdb-dialog-cancel').click();
                    $('.check-all-icon').removeClass('checkAll').addClass('checkNone');
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '批量编辑成功.'}});
                    bdbMain.mLSleep({}, function() {
                        _this.list({page: _this.pageState.page});
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },

        /* 策略、指向选择 */
        policySelEvent: function() {
            // 策略选择.
            $('form select[name="policy_id"]').off('change.policySel').on('change.policySel', function(e) {
                e.stopPropagation();
                var form = $(this).parents('form'),
                    rightEle = form.find('.platdomainpolicy-policy-right');

                if ($(this).val() != 0) { // 隐藏指向.
                    rightEle.hide();
                    rightEle.find('div[id*="-error"]').remove();
                    rightEle.find('select[name="record_type"]').val('A');
                    rightEle.find('textarea[name="ips"]').val('').show();
                    rightEle.find('input[name="cname"]').val('').hide();
                } else { // 显示指向.
                    rightEle.show();
                }
            });

            // 指向选择.
            $('form select[name="record_type"]').off('change.recordType').on('change.recordType', function(e) {
                e.stopPropagation();
                var form = $(this).parents('form'),
                    rightEle = form.find('.platdomainpolicy-policy-right');

                rightEle.find('div[id*="-error"]').remove();
                if ($(this).val() == 'A') { // A记录.
                    rightEle.find('textarea[name="ips"]').show();
                    rightEle.find('input[name="cname"]').val('').hide();
                } else { // CNAME.
                    rightEle.find('textarea[name="ips"]').val('').hide();
                    rightEle.find('input[name="cname"]').show();
                }
            });
        },

        /* 列表 */
        listEvent: function() {
            var _this = this;
            $('.bdb-list').off('click.listEvent').on('click.listEvent', function(e) {
                var ele = $(e.target),
                    id = ele.parents('.bdb-list-row').attr('data-id');

                if (ele.parents('.js-bdb-prevent-bubble').length || ele.hasClass('js-bdb-prevent-bubble')) {
                    e.stopPropagation();
                }

                if (ele.hasClass('js-platdomainpolicy-del')) { // 删除.
                    _this.listDel(id);
                } else if (ele.hasClass('js-platdomainpolicy-edit')) { // 编辑.
                    _this.listEdit(id);
                }
            });
        },
        listEdit: function(id) {
            var _this = this;
            bdbMain.mLRManag({mask: true, loading: true});
            $.post('/PlatDomainLine/editLineInit', {
                plat_domain_line_id: id
            }, function(response) {
                if (response.code == 0) {
                    _this.listEditProc(response.data);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        listEditProc: function(data) {
            var _this = this;
            $.post('/PlatDomainLine/policyLineInit', {
                plat_domain_id: _this.defData.platDomainId,
                type: 1
            }, function(response) {
                if (response.code == 0) {
                    _this.listEditTpl(data, response.data);
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }
            }, 'json');
        },
        listEditTpl: function(data, initData) {
            var _this = this,
                policyHtml = '',
                ips = '',
                ele = $('#bdb-platdomainpolicy-edit-form');

            // 策略.
            $.each(initData.policyList, function(i, n) {
                policyHtml += '<option value="' + n.policy_id + '">' + n.policy_name + '</option>';
            });

            // 指向.
            $.each(data.ips, function(i, n) {
                ips += n + "\n";
            });

            // 赋值.
            ele.find('#plat_domain_line_id-edit').val(data.plat_domain_line_id);
            ele.find('.title span').html(initData.domain);
            ele.find('#policy_id-edit').html(policyHtml).val(data.policy_id);
            ele.find('#record_line_name-edit').val(data.record_line_name);
            ele.find('#ttl-edit').val(data.ttl);
            if (data.policy_id != 0) { // 有策略.
                ele.find('#record_type-edit').val('A');
                ele.find('#ips-edit').val('').show();
                ele.find('#cname-edit').val('').hide();
                ele.find('.platdomainpolicy-policy-right').hide();
            } else { // 无策略.
                if (data.record_type == 'A') {
                    ele.find('#ips-edit').val(ips).show();
                    ele.find('#cname-edit').val('').hide();
                } else {
                    ele.find('#ips-edit').val('').hide();
                    ele.find('#cname-edit').val(ips).show();
                }

                ele.find('#record_type-edit').val(data.record_type);
                ele.find('.platdomainpolicy-policy-right').show();
            }

            _this.listEditVerify();
        },
        listEditVerify: function() {
            var _this = this,
                formVerify;

            formVerify = $('#bdb-platdomainpolicy-edit-form').validate({
                errorElement: "div",
                errorPlacement: function(error, element) {
                    error.addClass("help-block");
                    if (element.prop("type") === "checkbox" || element.prop("type") === "radio") {
                        element.parents(".bdb-vc").find('.help-block').remove();
                        error.appendTo(element.parents(".bdb-vc"));
                    } else {
                        error.insertAfter(element);
                    }
                },
                submitHandler: function(form, e) {
                    e.preventDefault();
                    _this.listEditSave(form);
                }
            });

            bdbMain.mLSleep({loading: false}, function() {
                $(".bdbBlankEle").bdbDialog({
                    ele: '#bdb-platdomainpolicy-edit-dialog',
                    formObj: formVerify,
                    form: $('#bdb-platdomainpolicy-edit-form'),
                    verifyResetInfo: true
                });
            });
        },
        listEditSave: function(form) {
            var _this = this,
                form = $(form);

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            var ips = '',
                ipsArr = [];

            if (form.find('#record_type-edit').val() == 'A') {
                ips = form.find('#ips-edit').val().trim();
                ipsArr = ips.split('\n');
                ips = ipsArr.join(',');
            } else {
                ips = form.find('#cname-edit').val();
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, maskUp: 101, loading: true});
            $.post('/PlatDomainLine/editLine', {
                plat_domain_line_id: form.find('#plat_domain_line_id-edit').val(),
                record_type: form.find('#record_type-edit').val(),
                policy_id: form.find('#policy_id-edit').val(),
                ttl: form.find('#ttl-edit').val(),
                ips: ips
            }, function(response) {
                if (response.code == 0) {
                    $('.js-bdb-dialog-cancel').click();
                    bdbMain.mLRManag({maskDown: 99, loading: false, alert: {type: 1, msg: '编辑成功.'}});
                    bdbMain.mLSleep({}, function() {
                        _this.list({page: _this.pageState.page});
                    });
                } else {
                    bdbMain.mLSleep({maskDown: 99, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        listDel: function(id) {
            var _this = this;

            bdbMain.confirm({
                textInfo: {
                    content: '确定要删除这条记录？',
                    btn: {}
                },
                // note: true,
                params: {
                    url: '/PlatDomainLine/deleteLine',
                    data: {
                        id: id
                    }
                },
                callback: function(ele, params) {
                    _this.listDelCallbackProc(ele, params);
                }
            });
        },
        listDelCallbackProc: function(ele, params) {
            var _this = this;
            ele.hide();

            // 请求已发出.
            if (!bdbMain.ajaxInfo.state) {
                bdbMain.mLRManag({alert: {type: 2, msg: bdbMain.ajaxInfo.text}});
                return ;
            }

            // 发送请求.
            bdbMain.ajaxInfo.state = 0; // 加锁.
            bdbMain.mLRManag({mask: true, loading: true});
            $.post(params.url, {
                plat_domain_line_id: params.data.id
            }, function(response) {
                if (response.code == 0) {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 1, msg: '删除成功'}}, function() {
                        bdbMain.mLSleep({}, function() {
                            _this.list({page: bdbMain.pageCheck(_this.pageState.page)});
                        });
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }

                bdbMain.ajaxInfo.state = 1; // 释放锁.
            });
        },
        list: function(obj) {
            var _this = this,
                obj = obj || {page: 1};

            _this.pageState.page = obj.page;
            bdbMain.mLRManag({mask: true, loading: true});

            // 获取列表.
            $.post('/PlatDomainLine/lineList', {
                pageSize: _this.defData.pageSize,
                pageNumber: _this.pageState.page,
                plat_domain_id: _this.defData.platDomainId
            }, function(response) {
                if (response.code == 0 ) {
                    var listHtml = _this.listProc(response.data.list),
                        totalRowCnt = parseInt(response.data.totalCount) > 0 ? parseInt(response.data.totalCount) : 0;

                    _this.listNull(totalRowCnt);
                    $('.bdb-list').html(listHtml);
                    bdbMain.mLSleep({mask: false, loading: false});

                    // 分页插件.
                    $("#js-bdb-creatPage").bdbPagination({
                        totalRowCnt: totalRowCnt,
                        currentPage: _this.pageState.page,
                        pageSize: _this.defData.pageSize
                    });
                    $('.bdb-record-cnt').html(bdbMain.pageInfo.recordCnt.replace('{cnt}', totalRowCnt));

                    // tip.
                    $('.js-platdomainpolicy-tip').bdbTip({
                        eleTopMargin: 129,
                        eleBottomMargin: 53,
                        space: 0,
                        left: 0,
                        minWidth: 220,
                        maxWidth: 220,
                        padding: '6px 24px 6px 26px',
                        tpl: '<div class="col-md-12 bdb-ellipsis bdb-text-align-l">{data}</div>'
                    });
                } else {
                    bdbMain.mLSleep({mask: false, loading: false, alert: {type: 2, msg: response.msg}});
                }

                $('.check-all-icon').removeClass('checkAll').addClass('checkNone'); // 撤销全选.
            }, 'json');
        },
        listProc: function(list) {
            var _this = this,
                tplHtml = '',
                recordListText,
                policyName,
                pointText,
                state;

            $.each(list, function(i, n) {
                state = '';
                recordListText = '';
                policyName = '无';
                pointText = '无';

                // 记录值.
                recordListText = n.ip_list.join(" / ");

                // 策略名称.
                if (n.policy_name != '') {
                    policyName = n.policy_name;
                } else {
                    pointText = recordListText;
                }

                // 策略(0：未下发；1：已生效；2：已下发).
                if (n.status == 0) {
                    state = '未下发';
                } else if (n.status == 1) {
                    state = '已生效';
                } else if (n.status == 2) {
                    state = '已下发';
                }

                tplHtml += "<div class='bdb-list-row' data-id='" + n.plat_domain_line_id + "'>\
                                <div class='bdb-mx-w-col-1 check-icon checkNo'></div>\
                                <div class='bdb-mx-w-col-2 bdb-ellipsis'>" + n.record_line_name + "</div>\
                                <div class='bdb-mx-w-col-3 bdb-ellipsis'>" + policyName + "</div>\
                                <div class='bdb-mx-w-col-4 bdb-ellipsis'>" + n.ttl + "</div>\
                                <div class='bdb-mx-w-col-5 bdb-ellipsis'>" + pointText + "</div>\
                                <div class='bdb-mx-w-col-6 bdb-p-r'>\
                                    <div class='" + (n.ip_list != '' ? "js-platdomainpolicy-tip " : "") + "bdb-ellipsis' \
                                        data-title='" + JSON.stringify(n.ip_list) + "'>" + recordListText + "</div>\
                                </div>\
                                <div class='bdb-mx-w-col-7'>" + state + "</div>\
                                <div class='bdb-mx-w-col-8'>\
                                    <div class='bdb-option-btn bdb-p-r bdb-mgn-t-10 js-bdb-prevent-bubble'>\
                                        <a class='js-platdomainpolicy-edit' href='javascript:void(0);'>编辑</a>\
                                        <!-- div class='v-line-ffa007'></div -->\
                                        <!-- a class='bdb-f-c-c8baac bdb-mgn-l--1 js-platdomainpolicy-del' href='javascript:void(0);'>删除</a -->\
                                    </div>\
                                </div>\
                            </div>";
            });

            return tplHtml;
        },
        listNull: function(totalRowCnt) {
            var noResult = $('.bdb-no-result'),
                noSearchRecord = $('.bdb-no-search-record');

            if (totalRowCnt <= 0) {
                if (this.pageState.noData == 'search') { // 查询.
                    noResult.hide();
                    noSearchRecord.show();
                } else { // 暂无记录.
                    noResult.show();
                    noSearchRecord.hide();
                }
            } else {
                noResult.hide();
                noSearchRecord.hide();
            }
        },

        /* 分页 */
        pageEvent: function() {
            var　_this = this;

            /* 页码事件 */
            $('.bdb-creatPage').off('click').on('click', '.bdb-pagination', function(e) {
                e.preventDefault();
                var ele = $(e.target),
                page = parseInt(ele.text());

                if (!isNaN(page)) {
                    _this.list({page: page});
                }
            });
        },

        /* 屏幕高度适应 */
        contentSizeResize: function() {
            $(window).resize(function() {
                $('.bdb-list').bdbScreenH(3);
            });
        },

        /* 线路选择 */
        lineSelEvent: function() {
            var _this = this,
                ele = $('#bdb-platdomainpolicy-add-form'),
                rightEle = ele.find('.platdomainpolicy-view-right');

            // 区域选择.
            ele.find('.platdomainpolicy-view-left').off('click').on('click', 'li', function() {
                var type = $(this).attr('data-type');
                if (type == 'all' && (rightEle.find('.check-icon').length == rightEle.find('.check-icon.checkYes').length)) { // 取消全选.
                    rightEle.find('.check-icon').addClass('checkNo').removeClass('checkYes'); // 全选.
                } else if (type == 'all') {
                    rightEle.find('.check-icon').addClass('checkYes').removeClass('checkNo');
                }else {
                    _this.lineSelAreaPosition(type, ele);
                }
            });

            // 单条线路选择.
            rightEle.off('click.lineSelSingle').on('click.lineSelSingle', '.area-subline', function(e) {
                _this.lineSel($(this), 'single');
            });

            // 整条线路选择.
            rightEle.off('click.lineSelSuball').on('click.lineSelSuball', '.area-title', function(e) {
                _this.lineSel($(this), 'subAll');
            });
        },
        lineSelAreaPosition: function(type, form) {
            form.find('.platdomainpolicy-view-right').scrollTop(this.defData.lineSelAreaInitialPosition[type]);
        },
        lineSel: function(ele, type) {
            var checkedEle;
            if (type == 'single') { // 选择单条.
                checkedEle = ele.find('i');
                if (checkedEle.hasClass('checkNo')) {
                    checkedEle.addClass('checkYes').removeClass('checkNo');
                } else { // 区域线路选择.
                    checkedEle.addClass('checkNo').removeClass('checkYes');
                }

                // 是否子线路都选择.
                var parentEle = ele.parent(),
                    prevCheckEle = parentEle.prev().find('i'),
                    allSubLine = parentEle.find('li').length,
                    allCheckedSubline = parentEle.find('li i.checkYes').length;

                if (allSubLine == allCheckedSubline) {
                    prevCheckEle.addClass('checkYes').removeClass('checkNo');
                } else {
                    prevCheckEle.addClass('checkNo').removeClass('checkYes');
                }
            } else {
                var sublineEle = ele.parent().next().find('li i');
                checkedEle = ele.find('i');
                if (checkedEle.hasClass('checkNo')) {
                    checkedEle.addClass('checkYes').removeClass('checkNo');
                    sublineEle.addClass('checkYes').removeClass('checkNo');
                } else {
                    checkedEle.addClass('checkNo').removeClass('checkYes');
                    sublineEle.addClass('checkNo').removeClass('checkYes');
                }
            }
        },

        init: function() {
            var _this = this;

            _this.list();
            _this.listEvent();
            _this.lineSelEvent();
            _this.policySelEvent();
            _this.addEvent();
            _this.pageEvent();
            _this.allPushEvent();
            _this.batchEditEvent();
            _this.contentSizeResize();

            $('.bdb-container').bdbCheckBox(); // 全选插件调用.
            $('.bdb-list').bdbScreenH(3);
        }
    };

    bdbplatDomainLine.init();
});
